<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<div class="setp_main">
	<table class="table" cellpadding="0" cellspacing="0" style="width:100%;table-layout: fixed;">
		<tr class="title">
			<td width="285px"><span class="stress">*</span>&nbsp;<s:property value="#orgTxt"/>ORG：</td>
			<td width="150px">&nbsp;</td>
			<td><span class="stress">*</span>&nbsp;<s:property value="#desTxt"/>DES：</td>
		</tr>
		<tr>
			<td>
            	<input type="text" id="pointORG" name="pointORG" value="<s:property value="work.pointORG.fullname" />" autocomplete="off" tabindex="1"
            		onkeyup="seachDataByKeyword('searchPointBykeyword?portType=0',this.value,'pointORG','pointORGId',0,235);" onblur="inputPoint()" />
           		<input type="hidden" id="pointORGId" name="work.pointORG.id" value="<s:property value="work.pointORG.id" />"/>
				<a id="orgInfoBtn" href="javascript:openPopDiv('orgInfo')" class="btn_info">&nbsp;</a>
			</td>
			<td align="center" id="transhipType1Td">
				<img src="${pageContext.request.contextPath}/cts/images/arrow_r.png"/>
			</td>
			<td>
            	<input type="text" id="pointDES" name="pointDES" value="<s:property value="work.pointDES.fullname" />" autocomplete="off" tabindex="2"
            		onkeyup="seachDataByKeyword('searchPointBykeyword?portType=0',this.value,'pointDES','pointDESId',0,235);" onblur="inputPoint()" />
           		<input type="hidden" id="pointDESId" name="work.pointDES.id" value="<s:property value="work.pointDES.id" />"/>
				<a id="desInfoBtn" href="javascript:openPopDiv('desInfo')" class="btn_info">&nbsp;</a>
			</td>
		</tr>
		<tr class="title">
			<td colspan="3">
				<div style="width: 90%; height:110px; margin-left:8px; border:1px dashed #676767; text-align: center;word-wrap: break-word; ">
					<br style="line-height: 25px;" />
					<span class="stress">*</span>&nbsp;箱量：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<br />
					<br id="boxTitle" style="line-height: 10px;" />
					<s:if test="work.boxAmount != null && work.boxAmount != ''">
						<span id="boxSpan"><s:property value="work.boxAmount"/></span><br />
						<br style="line-height: 10px;" />
					</s:if>
					<a href="javascript:openPopDiv('boxAmountDiv','showBoxAmount?workId=<s:property value="work.id" />')" style="color: blue">点击此处添加</a>
				</div>
			</td>
		</tr>
	</table>
	<table class="table" cellpadding="0" cellspacing="0" style="width: 100%; margin-top:50px; table-layout: fixed;">
		<tr class="title">
			<td width="210px;">&nbsp;&nbsp;运输公司：</td>
			<td width="150px;">&nbsp;&nbsp;订舱号：</td>
			<td>&nbsp;&nbsp;车牌号：</td>
		</tr>
		<tr>
			<td style="white-space: nowrap">
				<s:select id="carrier" name="work.carrier.id" cssStyle="width:200px"
					list="#request.allCarrier" headerKey="0" headerValue="请选择" listKey="id" listValue="name" value="work.carrier.id"></s:select>
				<font style="line-height: 47px; margin-left: -40px;">&nbsp;</font>
			</td>
			<td><input type="text" id="bookingNumber" name="work.bookingNumber" value="<s:property value="work.bookingNumber" />" style="width:130px"/></td>
			<td><input type="text" id="truckingCarNumber" name="work.truckingCarNumber" value="<s:property value="work.truckingCarNumber" />" style="width:130px"/></td>
		</tr>
		<tr class="title">
			<td width="210px;">&nbsp;&nbsp;司机：</td>
			<td>&nbsp;&nbsp;电话：</td>
		</tr>
		<tr>
			<td><input type="text" id="truckingDriver" name="work.truckingDriver" value="<s:property value="work.truckingDriver" />" style="width: 180px"/></td>
			<td><input type="text" id="truckingTel" name="work.truckingTel" v_tips="nullable,mobileOrTel" value="<s:property value="work.truckingTel" />"/></td>
		</tr>
		<tr class="title">
			<td colspan="4">&nbsp;&nbsp;运输要求：</td>
		</tr>
		<tr>
			<td colspan="4">
				<textarea id="deliveryRequirements" name="work.deliveryRequirements" class="input_xxl jNiceTextarea"><s:property value="work.deliveryRequirements"/></textarea>
			</td>
		</tr>
		<tr class="title">
			<td colspan="4">&nbsp;&nbsp;运输反馈：</td>
		</tr>
		<tr>
			<td colspan="4">
				<textarea id="deliveryFeedback" name="work.deliveryFeedback" class="input_xxl jNiceTextarea"><s:property value="work.deliveryFeedback"/></textarea>
			</td>
		</tr>
	</table>
</div>
<!-- 出发地信息 -->
<div id="orgInfo" class="popdiv_inner">
	<div class="popdiv_inner_outter"></div>
	<div class="popdiv_close" onclick="cancelPointInfo('orgInfo')"></div>
	<div class="popdiv_handle" style="font-size: 12px;" title="鼠标左键按住可拖动"><s:property value="#orgTxt"/>信息</div>
	<div class="popdiv_content" style="500px">
		<table style="width: 100%; font-size: 14px; border-bottom: 1px solid #d0d0d0;">
			<tr>
				<td align="right">收货地址：</td>
				<td>
					<input type="text" id="truckingAddress1" name="work.truckingAddress1" value="<s:property value="work.truckingAddress1" />">
					<input type="hidden" id="truckingAddress1Hide" value="<s:property value="work.truckingAddress1" />" />
				</td>
			</tr>
			<tr>
				<td align="right"><span class="stress">*</span>ETD：</td>
				<td>
					<input type="text" id="truckingETD" name="work.truckingETD" class="calendar" onclick="WdatePicker()" value="<s:date name="work.truckingETD" format="yyyy-MM-dd" />" >
					<input type="hidden" id="truckingETDHide" value="<s:date name="work.truckingETD" format="yyyy-MM-dd" />" />
				</td>
			</tr>
			<tr>
				<td align="right">出发时间：</td>
				<td>
					<input type="text" id="truckingTime1" name="work.truckingTime1" class="calendar" onclick="WdatePicker()" value="<s:date name="work.truckingTime1" format="yyyy-MM-dd" />" >
					<input type="hidden" id="truckingTime1Hide" value="<s:date name="work.truckingTime1" format="yyyy-MM-dd" />" />
				</td>
			</tr>
		</table>
		<div style="text-align: right; padding-top: 5px;">
			<input type="button" value="确认" onclick="savePointInfo('orgInfo');isInfo('truckingETD')" style="width: auto;" />&nbsp;
			<input type="button" value="取消" onclick="hidePopDiv('orgInfo')" style="width: auto;" />
		</div>
	</div>
</div>

<!-- 目的地信息 -->
<div id="desInfo" class="popdiv_inner">
	<div class="popdiv_inner_outter"></div>
	<div class="popdiv_close" onclick="cancelPointInfo('desInfo')"></div>
	<div class="popdiv_handle" style="font-size: 12px;" title="鼠标左键按住可拖动"><s:property value="#desTxt"/>信息</div>
	<div class="popdiv_content" style="500px">
		<table style="width: 100%; font-size: 14px; border-bottom: 1px solid #d0d0d0;">
			<tr>
				<td align="right">送货地址：</td>
				<td>
					<input type="text" id="truckingAddress2" name="work.truckingAddress2" value="<s:property value="work.truckingAddress2" />" >
					<input type="hidden" id="truckingAddress2Hide" value="<s:property value="work.truckingAddress2" />" />
				</td>
			</tr>
			<tr>
				<td align="right"><span class="stress">*</span>ETA：</td>
				<td>
					<input type="text" id="truckingETA" name="work.truckingETA" class="calendar" onclick="WdatePicker()" value="<s:date name="work.truckingETA" format="yyyy-MM-dd" />" >
					<input type="hidden" id="truckingETAHide" value="<s:date name="work.truckingETA" format="yyyy-MM-dd" />" />
				</td>
			</tr>
			<tr>
				<td align="right">到达时间：</td>
				<td>
					<input type="text" id="truckingTime2" name="work.truckingTime2" class="calendar" onclick="WdatePicker()" value="<s:date name="work.truckingTime2" format="yyyy-MM-dd" />" >
					<input type="hidden" id="truckingTime2Hide" value="<s:date name="work.truckingTime2" format="yyyy-MM-dd" />" />
				</td>
			</tr>
			<tr>
				<td align="right">放货代理：</td>
				<td>
					<input type="text" id="truckingAgent" name="truckingAgent" value="<s:property value="work.truckingAgent.nickname" />"
						onkeyup="seachDataByKeyword('searchEmployeeBykeyword.action?type=1',this.value,'truckingAgent','truckingAgentId',0,150);" style="width:150px">
					<input type="hidden" id="truckingAgentId" name="work.truckingAgent.id" value="<s:property value="work.truckingAgent.id" />">
					<input type="hidden" id="truckingAgentHide" value="<s:property value="work.truckingAgent.nickname" />">
					<input type="hidden" id="truckingAgentIdHide" value="<s:property value="work.truckingAgent.id" />">
					<a href="javascript:addEmployee('truckingAgent')" class="add_btn">&nbsp;</a>
					<font style="line-height: 56px;">&nbsp;</font>
				</td>
			</tr>
		</table>
		<div style="text-align: right; padding-top: 5px;">
			<input type="button" value="确认" onclick="savePointInfo('desInfo');isInfo('truckingETA')" style="width: auto;" />&nbsp;
			<input type="button" value="取消" onclick="hidePopDiv('desInfo')" style="width: auto;" />
		</div>
	</div>
</div>
<script>
$(function(){
	$('#truckingAddress1,#truckingAddress2').each(function(){$(this).pleaseInput()});
})

var preErrorId = [];
function validateForm(){
	var errorId = [];
	var errorMsg = '';
	var orgId = $('#pointORGId').val();
	var desId = $('#pointDESId').val();
	if(orgId == ''){
		errorId[errorId.length] = 'pointORG';
		errorMsg += '<s:property value="#orgTxt" escape="false"/>不能为空\r\n';
	}
	if(desId == ''){
		errorId[errorId.length] = 'pointDES';
		errorMsg += '<s:property value="#desTxt" escape="false"/>不能为空\r\n';
	}
	if(orgId != '' && desId != '' && orgId == desId){  //出发地和目的地
		errorId[errorId.length] = 'pointORG';
		errorId[errorId.length] = 'pointDES';
		errorMsg += '<s:property value="#orgTxt" escape="false"/>和<s:property value="#desTxt" escape="false"/>不能相同\r\n';
	}
	if($('#truckingTel').val().trim() != '' && !$('#truckingTel')[0].startValidateTips()){
		errorId[errorId.length] = 'truckingTel';
		errorMsg += '电话输入不正确\r\n';
	}
	if(isInfo('truckingETD')){ //出发地信息
		errorMsg += '<s:property value="#orgTxt" escape="false"/>信息\r\n';
	}
	if(isInfo('truckingETA')){ //目的地信息
		errorMsg += '<s:property value="#desTxt" escape="false"/>信息\r\n';
	}
	if(typeof saveAllWorkItem == 'function'){
		errorMsg += saveAllWorkItem();
	}
	for(i=0; i<preErrorId.length; i++){
		normalCssJNice(preErrorId[i]);
	}
	if(errorMsg != ''){
		preErrorId = errorId;
		for(i=0; i< errorId.length; i++){
			errorCssJNice(errorId[i]);
		}
		alert(errorMsg);
		return;
	}
	if($('#truckingAgentId').val() == ''){
		$('#truckingAgentId').val(0);
	}
	$('#truckingAddress1,#truckingAddress2').each(function(){ this.isInput(true) });
	var params = $("#workForm").serialize();
	$('#truckingAddress1,#truckingAddress2').each(function(){ this.isInput(false) });
	$.post('cts/workStep3?save=true',params,function(result){
		if(result.trim() == 'null'){
			alert('订单不存在或已经被删除');
		}else if(result.trim() == 'status5'){
			alert('该订单已归档');
		}else if(result.trim() == 'ok'){
			nextStep();
		}else{
			alert('保存失败');
		}
	})
}
//是否正确输入地点信息
function isInfo(id){
	var infoBtn = {'truckingETD':'orgInfoBtn','truckingETA':'desInfoBtn'}
	var isInfo = false;
	if($('#'+id).val() == ''){
		errorCssJNice(id);
		$('#'+infoBtn[id])[0].className = 'btn_info_red';
		isInfo = true;
	}else{
		normalCssJNice(id);
		$('#'+infoBtn[id])[0].className = 'btn_info';
		isInfo = false;
	}
	return isInfo;
}
//保存地点信息
function savePointInfo(div){
	$('#'+div).find('input:text,input:hidden').each(function(){
		if($('#'+this.id+'Hide').length > 0)
			$('#'+this.id+'Hide').val(this.value);
	})
	hidePopDiv(div);
	$('#oceanVessel1,#voyNo1,#oceanVessel2,#voyNo2').each(function(){$(this).pleaseInput()});
}
//取消还原地点信息
function cancelPointInfo(div){
	$('#'+div).find('input:text,input:hidden').each(function(){
		if($('#'+this.id+'Hide').length > 0)
			this.value = $('#'+this.id+'Hide').val();
	})
	$('#oceanVessel1,#voyNo1,#oceanVessel2,#voyNo2').each(function(){$(this).pleaseInput()});
}
function inputPoint(){
	if(typeof changeTypeDetail == 'function') changeTypeDetail();
}
</script>